package com.xbb.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xbb.entity.Computer;
import com.xbb.entity.dto.ComputerDto;
import com.xbb.service.ComputerService;
import com.xbb.util.Result;

@RestController
public class ComputerController {

	@Autowired
	ComputerService computerService;
	
	@RequestMapping("/getComList")
	public Object getComList(ComputerDto computerDto,ModelMap map) {
		List<ComputerDto> list = computerService.getComs(computerDto);
		computerDto.setLimit(null);
		computerDto.setPage(null);
		List<ComputerDto> list2 = computerService.getComs(computerDto);
		return new Result(0,"",list2.size(),list);
	}
	
	
	@RequestMapping("/addCom")
	public Object addCom(Computer computer) {
		if(computerService.addCom(computer)) {
			return new Result(0,"添加成功");
		}else {
			return new Result(1,"添加失败");
		}
	}
	
	@RequestMapping("/updateCom")
	public Object updateCom(Computer computer) {
		if(computerService.updateCom(computer)) {
			return new Result(0,"修改成功");
		}else {
			return new Result(1,"修改失败");
		}
	}
	
	@RequestMapping("/delCom")
	public Object delCom(int cid) {
		if(computerService.delCom(cid)) {
			return new Result(0,"删除成功");
		}else {
			return new Result(1,"删除失败");
		}
	}
	
	
}
